package cn.merryyou.security.domain;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonInclude;


/**
 * @Author: [zhangzhiguang]
 * @Date: [2018-08-01 23:39]
 * @Description: [ ]
 * @Version: [1.0.0]
 * @Copy: [com.zzg]
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> implements Serializable {

    private static final long serialVersionUID = -4696008537295855861L;
    private T data;
    private int code;
    private String msg;

	public Result() {
		this(CodeEnum.OK.getCode(), CodeEnum.OK.getMsg());
	}


	public Result(int code, String msg) {
		this(code, msg, null);
	}

	public Result(int code, String msg, T data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}
	
	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public static <T> Result<T> ok() {
        return ok(CodeEnum.OK.getMsg());
    }
	public static <T> Result<T> ok(String msg) {
        return ok(msg,null);
    }
    public static <T> Result<T> ok(T data) {
        return ok(CodeEnum.OK.getMsg(), data);
    }

    public static <T> Result<T> ok(String msg,T data) {
        return ok(CodeEnum.OK.getCode(), msg, data);
    }

    public static <T> Result<T> ok(int code, String msg, T data) {
        return new Result<T>(code, msg, data);
    }
    
	public static <T> Result<T> error() {
        return error(CodeEnum.ERROR.getMsg());
    }

    public static <T> Result<T> error(T data) {
        return error(CodeEnum.ERROR.getMsg(), data);
    }

    public static <T> Result<T> error(String msg) {
        return error(msg, null);
    }

    public static <T> Result<T> error(String msg,T data) {
        return error(CodeEnum.ERROR.getCode(), msg, data);
    }
    
    public static <T> Result<T> error(int code, String msg) {
        return new Result<T>(code, msg);
    }

    public static <T> Result<T> error(int code, String msg, T data) {
        return new Result<T>(code, msg, data);
    }

}
